--清理协议
local qinglixieyi = fk.CreateSkill {
    name = "mcdh_qinglixieyi",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

qinglixieyi:addEffect(fk.CardUseFinished,{
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(self) and data.card.trueName == "slash" and #TargetGroup:getRealTargets(data.tos) == 1 and not player:isNude() and player:getMark("mcdh_ammo") >= 2
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local befto = TargetGroup:getRealTargets(data.tos)[1]
        local ids,cards = room:askForChooseCardAndPlayers(player,table.map(room:getOtherPlayers(player),Util.IdMapper),1,1,".","#mcdh_qinglixieyi_choose",true)
        if #ids > 0 then
            local to = room:getPlayerById(ids[1])
            room:moveCardTo(cards, Card.PlayerHand, to, fk.ReasonGive, self.name, nil, false, player.id)
            room:setPlayerMark(to,"@#mcdh_qinglixieyi_givecard","")
            lib.mcdh_ammo(player, -2)
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = room:getPlayerById(TargetGroup:getRealTargets(data.tos)[1])
        if to.dead then
            return
        end
        local choices = {}
        local all_choices = {}
        local all_cards = Fk:getAllCardIds()
        table.sort(all_cards,function (a, b)
            local carda = Fk:getCardById(a)
            local cardb = Fk:getCardById(b)
            if carda.type == cardb.type then
                return a<b
            end
            return carda.type < cardb.type
        end)
        for _, id in ipairs(all_cards) do
            local card = Fk:getCardById(id)
            if (card:isCommonTrick() or card.name == "slash") and not card.is_derived then
                table.insertIfNeed(all_choices, card.name)
                if player:canUseTo(card,to,{bypass_times = true,bypass_distances = true})then
                    table.insertIfNeed(choices, card.name)
                end
            end
        end
        if #choices > 0 then
            U.askForUseVirtualCard (room, player, choices, nil, self.name, "#mcdh_qinglixieyi_usecard:"..to.id,false, true, true, true, {  must_targets= {to.id} })
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_qinglixieyi"] = "净除",
    [":mcdh_qinglixieyi"] = "『清理协议』<br>装填技(2)。当你使用仅指定唯一目标的【杀】结算后，你可以将一张牌交给一名其他角色，然后视为对此【杀】原目标使用一张不可响应的【杀】或普通锦囊牌。",
    ["#mcdh_qinglixieyi_choose"] = "清理协议：你可以交给一名其他角色一张牌。",
    ["#mcdh_qinglixieyi_usecard"] = "清理协议：你视为对%src使用一张不可响应、且无距离次数限制的【杀】或普通锦囊牌。",
    ["@#mcdh_qinglixieyi_givecard"] = "清理协议"
}

return qinglixieyi